gimp r27896 - in trunk: . plug-ins/common



Author: neo
Date: Tue Jan  6 22:42:47 2009
New Revision: 27896
URL: http://svn.gnome.org/viewvc/gimp?rev=27896&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/plug-ins/common/noise-hsv.c
   trunk/plug-ins/common/noise-rgb.c

Modified: trunk/plug-ins/common/noise-hsv.c
==============================================================================
--- trunk/plug-ins/common/noise-hsv.c	(original)
+++ trunk/plug-ins/common/noise-hsv.c	Tue Jan  6 22:42:47 2009
@@ -226,11 +226,12 @@
                  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 @@
   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 @@
       else
         new = min;
     }
+
   if (max < new)
     {
       if (wraps_around)
@@ -259,7 +261,8 @@
       else
         new = max;
     }
-  return new;
+
+  return (gint) (new + 0.5);
 }
 
 static void

Modified: trunk/plug-ins/common/noise-rgb.c
==============================================================================
--- trunk/plug-ins/common/noise-rgb.c	(original)
+++ trunk/plug-ins/common/noise-rgb.c	Tue Jan  6 22:42:47 2009
@@ -308,15 +308,15 @@
               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 @@
 
           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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]