From eeae281bc01e30eb71625dcdff39090f586cc06d Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 6 Jan 2009 22:42:47 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20566498=20=E2=80=93=20Noise=20distribution?= =?UTF-8?q?=20error=20in=20RGB=20Noise=20and=20HSV=20Noise?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2009-01-06 Sven Neumann 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 --- ChangeLog | 7 +++++++ plug-ins/common/noise-hsv.c | 11 +++++++---- plug-ins/common/noise-rgb.c | 13 +++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1115a20a2..ab3e38adc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-01-06 Sven Neumann + + 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 * app/widgets/gimpcombotagentry.c diff --git a/plug-ins/common/noise-hsv.c b/plug-ins/common/noise-hsv.c index 87a79497cc..7a4d58bc32 100644 --- a/plug-ins/common/noise-hsv.c +++ b/plug-ins/common/noise-hsv.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 diff --git a/plug-ins/common/noise-rgb.c b/plug-ins/common/noise-rgb.c index 313065531f..ce4f6b76b4 100644 --- a/plug-ins/common/noise-rgb.c +++ b/plug-ins/common/noise-rgb.c @@ -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