Commit d4b49c0c authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added a missing GimpHistogramChannel parameter. Fixes wrong values in the

2003-10-30  Sven Neumann  <sven@gimp.org>

	* app/base/gimphistogram.[ch] (gimp_histogram_get_count): added a
	missing GimpHistogramChannel parameter. Fixes wrong values in the
	histogram tool.

	* app/base/levels.c
	* app/base/lut-funcs.c
	* app/pdb/color_cmds.c
	* tools/pdbgen/pdb/color.pdb: changed accordingly.

	* app/tools/gimphistogramtool.c: update the histogram statistics
	on channel changes.
parent 7937639e
2003-10-30 Sven Neumann <sven@gimp.org>
* app/base/gimphistogram.[ch] (gimp_histogram_get_count): added a
missing GimpHistogramChannel parameter. Fixes wrong values in the
histogram tool.
* app/base/levels.c
* app/base/lut-funcs.c
* app/pdb/color_cmds.c
* tools/pdbgen/pdb/color.pdb: changed accordingly.
* app/tools/gimphistogramtool.c: update the histogram statistics
on channel changes.
2003-10-29 Sven Neumann <sven@gimp.org>
* app/gui/preferences-dialog.c: increased vertical spacing.
......@@ -54,11 +54,11 @@ struct _GimpHistogram
/* local function prototypes */
static void gimp_histogram_alloc_values (GimpHistogram *histogram,
static void gimp_histogram_alloc_values (GimpHistogram *histogram,
gint bytes);
static void gimp_histogram_free_values (GimpHistogram *histogram);
static void gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
PixelRegion *region,
PixelRegion *region,
PixelRegion *mask);
......@@ -105,7 +105,7 @@ gimp_histogram_free (GimpHistogram *histogram)
}
void
gimp_histogram_calculate (GimpHistogram *histogram,
gimp_histogram_calculate (GimpHistogram *histogram,
PixelRegion *region,
PixelRegion *mask)
{
......@@ -161,7 +161,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
}
gdouble
gimp_histogram_get_maximum (GimpHistogram *histogram,
gimp_histogram_get_maximum (GimpHistogram *histogram,
GimpHistogramChannel channel)
{
gdouble max = 0.0;
......@@ -177,8 +177,8 @@ gimp_histogram_get_maximum (GimpHistogram *histogram,
}
gdouble
gimp_histogram_get_value (GimpHistogram *histogram,
GimpHistogramChannel channel,
gimp_histogram_get_value (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint bin)
{
g_return_val_if_fail (histogram != NULL, 0.0);
......@@ -190,8 +190,8 @@ gimp_histogram_get_value (GimpHistogram *histogram,
}
gdouble
gimp_histogram_get_channel (GimpHistogram *histogram,
GimpHistogramChannel channel,
gimp_histogram_get_channel (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint bin)
{
g_return_val_if_fail (histogram != NULL, 0.0);
......@@ -199,7 +199,7 @@ gimp_histogram_get_channel (GimpHistogram *histogram,
if (histogram->n_channels > 3)
return gimp_histogram_get_value (histogram, channel + 1, bin);
else
return gimp_histogram_get_value (histogram, channel , bin);
return gimp_histogram_get_value (histogram, channel, bin);
}
gint
......@@ -211,9 +211,10 @@ gimp_histogram_nchannels (GimpHistogram *histogram)
}
gdouble
gimp_histogram_get_count (GimpHistogram *histogram,
gint start,
gint end)
gimp_histogram_get_count (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gint end)
{
gint i;
gdouble count = 0.0;
......@@ -221,15 +222,15 @@ gimp_histogram_get_count (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
for (i = start; i <= end; i++)
count += histogram->values[0][i];
count += histogram->values[channel][i];
return count;
}
gdouble
gimp_histogram_get_mean (GimpHistogram *histogram,
gimp_histogram_get_mean (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gint start,
gint end)
{
gint i;
......@@ -241,7 +242,7 @@ gimp_histogram_get_mean (GimpHistogram *histogram,
for (i = start; i <= end; i++)
mean += i * histogram->values[channel][i];
count = gimp_histogram_get_count (histogram, start, end);
count = gimp_histogram_get_count (histogram, channel, start, end);
if (count > 0.0)
return mean / count;
......@@ -250,9 +251,9 @@ gimp_histogram_get_mean (GimpHistogram *histogram,
}
gint
gimp_histogram_get_median (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gimp_histogram_get_median (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gint end)
{
gint i;
......@@ -261,7 +262,7 @@ gimp_histogram_get_median (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, -1);
count = gimp_histogram_get_count (histogram, start, end);
count = gimp_histogram_get_count (histogram, channel, start, end);
for (i = start; i <= end; i++)
{
......@@ -275,9 +276,9 @@ gimp_histogram_get_median (GimpHistogram *histogram,
}
gdouble
gimp_histogram_get_std_dev (GimpHistogram *histogram,
gimp_histogram_get_std_dev (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gint start,
gint end)
{
gint i;
......@@ -288,7 +289,7 @@ gimp_histogram_get_std_dev (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
mean = gimp_histogram_get_mean (histogram, channel, start, end);
count = gimp_histogram_get_count (histogram, start, end);
count = gimp_histogram_get_count (histogram, channel, start, end);
if (count == 0.0)
count = 1.0;
......@@ -304,7 +305,7 @@ gimp_histogram_get_std_dev (GimpHistogram *histogram,
/* private functions */
static void
gimp_histogram_alloc_values (GimpHistogram *histogram,
gimp_histogram_alloc_values (GimpHistogram *histogram,
gint bytes)
{
gint i;
......@@ -338,7 +339,7 @@ gimp_histogram_free_values (GimpHistogram *histogram)
static void
gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
PixelRegion *region,
PixelRegion *region,
PixelRegion *mask)
{
const guchar *src, *msrc;
......@@ -403,7 +404,7 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
}
break;
case 3: /* calculate seperate value values */
case 3: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
......@@ -422,7 +423,7 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
}
break;
case 4: /* calculate seperate value values */
case 4: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
......@@ -475,7 +476,7 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
}
break;
case 3: /* calculate seperate value values */
case 3: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
......@@ -492,7 +493,7 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
}
break;
case 4: /* calculate seperate value values */
case 4: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
......
......@@ -25,13 +25,14 @@
GimpHistogram * gimp_histogram_new (GimpBaseConfig *config);
void gimp_histogram_free (GimpHistogram *histogram);
void gimp_histogram_calculate (GimpHistogram *historgam,
void gimp_histogram_calculate (GimpHistogram *historgam,
PixelRegion *region,
PixelRegion *mask);
gdouble gimp_histogram_get_maximum (GimpHistogram *histogram,
GimpHistogramChannel channel);
gdouble gimp_histogram_get_count (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint start,
gint end);
gdouble gimp_histogram_get_mean (GimpHistogram *histogram,
......
......@@ -99,7 +99,7 @@ levels_channel_auto (Levels *levels,
levels->low_output[channel] = 0;
levels->high_output[channel] = 255;
count = gimp_histogram_get_count (hist, 0, 255);
count = gimp_histogram_get_count (hist, channel, 0, 255);
if (count == 0.0)
{
......
......@@ -343,7 +343,7 @@ typedef struct
} hist_lut_struct;
static gfloat
equalize_lut_func (hist_lut_struct *hlut,
equalize_lut_func (hist_lut_struct *hlut,
gint n_channels,
gint channel,
gfloat value)
......@@ -389,17 +389,19 @@ eq_histogram_lut_setup (GimpLut *lut,
g_return_if_fail (hist != NULL);
/* Find partition points */
pixels_per_value = gimp_histogram_get_count (hist, 0, 255) / 256.0;
pixels_per_value = gimp_histogram_get_count (hist,
GIMP_HISTOGRAM_VALUE,
0, 255) / 256.0;
for (k = 0; k < n_channels; k++)
{
/* First and last points in partition */
hlut.part[k][0] = 0;
hlut.part[k][256] = 256;
/* Find intermediate points */
j = 0;
sum = (gimp_histogram_get_channel (hist, k, 0) +
sum = (gimp_histogram_get_channel (hist, k, 0) +
gimp_histogram_get_channel (hist, k, 1));
for (i = 1; i < 256; i++)
......
......@@ -1055,8 +1055,8 @@ histogram_invoker (Gimp *gimp,
start_range, end_range);
median = gimp_histogram_get_median (histogram, channel,
start_range, end_range);
pixels = gimp_histogram_get_count (histogram, 0, 255);
count = gimp_histogram_get_count (histogram,
pixels = gimp_histogram_get_count (histogram, channel, 0, 255);
count = gimp_histogram_get_count (histogram, channel,
start_range, end_range);
percentile = count / pixels;
......
......@@ -66,13 +66,6 @@ struct _HistogramToolDialog
GimpHistogram *hist;
GtkWidget *gradient;
gdouble mean;
gdouble std_dev;
gdouble median;
gdouble pixels;
gdouble count;
gdouble percentile;
GimpDrawable *drawable;
};
......@@ -99,10 +92,13 @@ static void histogram_tool_dialog_update (HistogramToolDialog *htd,
gint start,
gint end);
static void histogram_tool_histogram_range (GimpHistogramView *view,
static void histogram_tool_range_changed (GimpHistogramView *view,
gint start,
gint end,
gpointer data);
static void histogram_tool_channel_notify (GimpHistogramView *view,
GParamSpec *pspec,
gpointer data);
static HistogramToolDialog * histogram_dialog = NULL;
......@@ -242,40 +238,27 @@ gimp_histogram_tool_control (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
/* histogram_tool machinery */
static void
histogram_tool_histogram_range (GimpHistogramView *widget,
gint start,
gint end,
gpointer data)
histogram_tool_range_changed (GimpHistogramView *view,
gint start,
gint end,
gpointer data)
{
HistogramToolDialog *htd;
GimpHistogramChannel channel;
gdouble pixels;
gdouble count;
HistogramToolDialog *htd = (HistogramToolDialog *) data;
htd = (HistogramToolDialog *) data;
if (htd == NULL || htd->hist == NULL ||
gimp_histogram_nchannels (htd->hist) <= 0)
return;
channel = gimp_histogram_view_get_channel (htd->histogram_box->histogram);
pixels = gimp_histogram_get_count (htd->hist, 0, 255);
count = gimp_histogram_get_count (htd->hist, start, end);
if (htd && htd->shell)
histogram_tool_dialog_update (htd, start, end);
}
htd->mean = gimp_histogram_get_mean (htd->hist, channel, start, end);
htd->std_dev = gimp_histogram_get_std_dev (htd->hist, channel, start, end);
htd->median = gimp_histogram_get_median (htd->hist, channel, start, end);
htd->pixels = pixels;
htd->count = count;
htd->percentile = count / pixels;
static void
histogram_tool_channel_notify (GimpHistogramView *view,
GParamSpec *pspec,
gpointer data)
{
HistogramToolDialog *htd = (HistogramToolDialog *) data;
if (htd->shell)
histogram_tool_dialog_update (htd, start, end);
if (htd && htd->shell)
histogram_tool_dialog_update (htd, view->start, view->end);
}
static void
......@@ -283,30 +266,46 @@ histogram_tool_dialog_update (HistogramToolDialog *htd,
gint start,
gint end)
{
gchar text[12];
GimpHistogramChannel channel;
gdouble pixels;
gdouble count;
gchar text[12];
if (! htd->hist || ! gimp_histogram_nchannels (htd->hist))
return;
channel = gimp_histogram_view_get_channel (htd->histogram_box->histogram);
pixels = gimp_histogram_get_count (htd->hist, channel, 0, 255);
count = gimp_histogram_get_count (htd->hist, channel, start, end);
/* mean */
g_snprintf (text, sizeof (text), "%3.1f", htd->mean);
g_snprintf (text, sizeof (text), "%3.1f",
gimp_histogram_get_mean (htd->hist, channel, start, end));
gtk_label_set_text (GTK_LABEL (htd->info_labels[0]), text);
/* std dev */
g_snprintf (text, sizeof (text), "%3.1f", htd->std_dev);
g_snprintf (text, sizeof (text), "%3.1f",
gimp_histogram_get_std_dev (htd->hist, channel, start, end));
gtk_label_set_text (GTK_LABEL (htd->info_labels[1]), text);
/* median */
g_snprintf (text, sizeof (text), "%3.1f", htd->median);
g_snprintf (text, sizeof (text), "%3.1f",
(gdouble) gimp_histogram_get_median (htd->hist,
channel, start, end));
gtk_label_set_text (GTK_LABEL (htd->info_labels[2]), text);
/* pixels */
g_snprintf (text, sizeof (text), "%8.1f", htd->pixels);
g_snprintf (text, sizeof (text), "%8.1f", pixels);
gtk_label_set_text (GTK_LABEL (htd->info_labels[3]), text);
/* count */
g_snprintf (text, sizeof (text), "%8.1f", htd->count);
g_snprintf (text, sizeof (text), "%8.1f", count);
gtk_label_set_text (GTK_LABEL (htd->info_labels[4]), text);
/* percentile */
g_snprintf (text, sizeof (text), "%2.2f", htd->percentile * 100);
g_snprintf (text, sizeof (text), "%4.1f", (pixels > 0 ?
(100.0 * count / pixels) : 0.0));
gtk_label_set_text (GTK_LABEL (htd->info_labels[5]), text);
}
......@@ -390,7 +389,11 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info)
gtk_widget_show (GTK_WIDGET (htd->histogram_box));
g_signal_connect (htd->histogram_box->histogram, "range_changed",
G_CALLBACK (histogram_tool_histogram_range),
G_CALLBACK (histogram_tool_range_changed),
htd);
g_signal_connect (htd->histogram_box->histogram, "notify::histogram-channel",
G_CALLBACK (histogram_tool_channel_notify),
htd);
/* The table containing histogram information */
......@@ -411,8 +414,8 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info)
GTK_FILL, GTK_FILL, 2, 2);
gtk_widget_show (label);
htd->info_labels[i] = gtk_label_new ("0");
gtk_misc_set_alignment (GTK_MISC (htd->info_labels[i]), 0.0, 0.5);
htd->info_labels[i] = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (htd->info_labels[i]), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), htd->info_labels[i],
x + 1, x + 2, y, y + 1,
GTK_FILL, GTK_FILL, 2, 2);
......
......@@ -676,8 +676,8 @@ HELP
start_range, end_range);
median = gimp_histogram_get_median (histogram, channel,
start_range, end_range);
pixels = gimp_histogram_get_count (histogram, 0, 255);
count = gimp_histogram_get_count (histogram,
pixels = gimp_histogram_get_count (histogram, channel, 0, 255);
count = gimp_histogram_get_count (histogram, channel,
start_range, end_range);
percentile = count / pixels;
......
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