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

Bug 566498 – Noise distribution error in RGB Noise and HSV Noise

2009-01-06  Sven Neumann  <sven@gimp.org>

	Bug 566498 – Noise distribution error in RGB Noise and HSV Noise

	* plug-ins/common/noise-hsv.c
	* plug-ins/common/noise-rgb.c: applied patch from Marco Rossini.


svn path=/trunk/; revision=27896
parent f81dedf3
2009-01-06 Sven Neumann <sven@gimp.org>
Bug 566498 Noise distribution error in RGB Noise and HSV Noise
* plug-ins/common/noise-hsv.c
* plug-ins/common/noise-rgb.c: applied patch from Marco Rossini.
2009-01-04 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcombotagentry.c
......
......@@ -226,11 +226,12 @@ randomize_value (gint now,
gboolean wraps_around,
gint rand_max)
{
gint flag, new, steps, index;
gdouble rand_val;
gint flag, steps, index;
gdouble rand_val, new;
steps = max - min + 1;
rand_val = g_random_double ();
for (index = 1; index < VALS.holdness; index++)
{
double tmp = g_random_double ();
......@@ -243,7 +244,7 @@ randomize_value (gint now,
else
flag = 1;
new = now + flag * ((int) (rand_max * rand_val) % steps);
new = now + flag * fmod (rand_max * rand_val, steps);
if (new < min)
{
......@@ -252,6 +253,7 @@ randomize_value (gint now,
else
new = min;
}
if (max < new)
{
if (wraps_around)
......@@ -259,7 +261,8 @@ randomize_value (gint now,
else
new = max;
}
return new;
return (gint) (new + 0.5);
}
static void
......
......@@ -308,15 +308,15 @@ noisify_func (const guchar *src,
gint bpp,
gpointer data)
{
GRand *gr = data;
gint noise = 0;
gint b;
GRand *gr = data;
gdouble noise = 0;
gint b;
for (b = 0; b < bpp; b++)
{
if (b == 0 || nvals.independent ||
(b == 1 && bpp == 2) || (b == 3 && bpp == 4))
noise = (gint) (nvals.noise[b] * gauss (gr) * 127);
noise = nvals.noise[b] * gauss (gr) * 127;
if (nvals.noise[b] > 0.0)
{
......@@ -324,12 +324,13 @@ noisify_func (const guchar *src,
if (nvals.correlated)
{
p = (gint) (src[b] + (src[b] * (noise / 127.0)));
p = (gint) (src[b] + (src[b] * (noise / 127.0)) + 0.5);
}
else
{
p = src[b] + noise;
p = (gint) (src[b] + noise + 0.5);
}
dest[b] = CLAMP0255 (p);
}
else
......
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