[gimp/metadata-browser] Bug 667368: Bug in Histogram egalization
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] Bug 667368: Bug in Histogram egalization
- Date: Wed, 12 Sep 2012 22:56:10 +0000 (UTC)
commit dfac0d6daf8bff82ae46b5e71376248f24dee9cd
Author: Massimo Valentini <mvalentini src gnome org>
Date: Thu Mar 8 18:20:45 2012 +0100
Bug 667368: Bug in Histogram egalization
app/base/lut-funcs.c | 47 +++++++++++------------------------------------
1 files changed, 11 insertions(+), 36 deletions(-)
---
diff --git a/app/base/lut-funcs.c b/app/base/lut-funcs.c
index fa1b9c0..de9d642 100644
--- a/app/base/lut-funcs.c
+++ b/app/base/lut-funcs.c
@@ -287,7 +287,7 @@ posterize_lut_new (gint levels,
typedef struct
{
GimpHistogram *histogram;
- gint part[5][257];
+ gint part[5][256];
} hist_lut_struct;
static gfloat
@@ -296,19 +296,15 @@ equalize_lut_func (hist_lut_struct *hlut,
gint channel,
gfloat value)
{
- gint i = 0;
gint j;
/* don't equalize the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels - 1)
return value;
- j = (gint) (value * 255.0 + 0.5);
+ j = RINT (CLAMP (value * 255.0, 0, 255));
- while (hlut->part[channel][i + 1] <= j)
- i++;
-
- return i / 255.0;
+ return hlut->part[channel][j] / 255.;
}
static void
@@ -316,48 +312,27 @@ equalize_lut_setup (GimpLut *lut,
GimpHistogram *hist,
gint n_channels)
{
- gint i, k, j;
+ gint i, k;
hist_lut_struct hlut;
- gdouble pixels_per_value;
- gdouble desired;
- gdouble sum, dif;
+ gdouble pixels;
g_return_if_fail (lut != NULL);
g_return_if_fail (hist != NULL);
/* Find partition points */
- pixels_per_value = gimp_histogram_get_count (hist,
- GIMP_HISTOGRAM_VALUE,
- 0, 255) / 256.0;
+ pixels = gimp_histogram_get_count (hist, GIMP_HISTOGRAM_VALUE, 0, 255);
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) +
- gimp_histogram_get_channel (hist, k, 1));
+ gdouble sum = 0;
- for (i = 1; i < 256; i++)
+ for (i = 0; i < 256; i++)
{
- desired = i * pixels_per_value;
-
- while (sum < desired && j < 256)
- {
- j++;
- sum += gimp_histogram_get_channel (hist, k, j + 1);
- }
+ gdouble histi = gimp_histogram_get_channel (hist, k, i);
- /* Nearest sum */
- dif = sum - gimp_histogram_get_channel (hist, k, j);
+ sum += histi;
- if ((sum - desired) > (dif / 2.0))
- hlut.part[k][i] = j;
- else
- hlut.part[k][i] = j + 1;
+ hlut.part[k][i] = RINT (sum * 255. / pixels);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]