Hija,

this is my suggested patch for getting the speeds improvements
as mentioned in the other thread by having a thread-local PRNG
initialized with a seed from the still existing blend tool local
RNG.

It looks bigger than it is because I took the liberty to remove
the nasty special casing on the existence of the RNG inside the
innermost loop because we now have it outside already.

There seems to be more room for obvious optimisations in the
loops. Also I would recommend splitting the two cases into
two separate functions to make the code easier to read, and
remove more conditionals.

PS: If this is okay, I'd do exactly the same for the gray
blending stuff...

diff -u -r1.155 gimpdrawable-blend.c
--- app/core/gimpdrawable-blend.c 26 Feb 2005 23:55:49 -0000 1.155
+++ app/core/gimpdrawable-blend.c 27 Feb 2005 14:55:36 -0000
@@ -1051,7 +1051,68 @@
gint endx = PR->x + PR->w;
gint endy = PR->y + PR->h;
gint x, y;
+
+ if (rbd->dither_rand)
+ {
+ GRand *localrand = g_rand_new_with_seed (g_rand_int (rbd->dither_rand));
+
+ for (y = PR->y; y < endy; y++)
+ {
+ for (x = PR->x; x < endx; x++)
+ {
+ GimpRGB color;
+ gdouble dither_prob;
+ gdouble ftmp;
+ gint itmp;
+
+ gradient_render_pixel (x, y, &color, rbd);
+
+ ftmp = color.r * 255.0;
+ itmp = ftmp;
+ dither_prob = ftmp - itmp;
+
+ if (g_rand_double (localrand) < dither_prob)
+ color.r += (1.0 / 255.0);
+
+ ftmp = color.g * 255.0;
+ itmp = ftmp;
+ dither_prob = ftmp - itmp;
+
+ if (g_rand_double (localrand) < dither_prob)
+ color.g += (1.0 / 255.0);
+
+ ftmp = color.b * 255.0;
+ itmp = ftmp;
+ dither_prob = ftmp - itmp;

+             if (g_rand_double (localrand) < dither_prob)
+               color.b += (1.0 / 255.0);
+
+             ftmp = color.a * 255.0;
+             itmp = ftmp;
+             dither_prob = ftmp - itmp;
+
+             if (g_rand_double (localrand) < dither_prob)
+               color.a += (1.0 / 255.0);
+
+             if (color.r > 1.0) color.r = 1.0;
+             if (color.g > 1.0) color.g = 1.0;
+             if (color.b > 1.0) color.b = 1.0;
+             if (color.a > 1.0) color.a = 1.0;
+
+             *dest++ = color.r * 255.0;
+             *dest++ = color.g * 255.0;
+             *dest++ = color.b * 255.0;
+             *dest++ = color.a * 255.0;
+           }
+       }
+
+      g_rand_free (localrand);
+
+      return;
+  }
+
+  /* Fall-through for non-dithering case */
   for (y = PR->y; y < endy; y++)
     {
       for (x = PR->x; x < endx; x++)
@@ -1059,46 +1120,6 @@
           GimpRGB  color;

           gradient_render_pixel (x, y, &color, rbd);
-
-          if (rbd->dither_rand)
-            {
-              gdouble dither_prob;
-              gdouble ftmp;
-              gint    itmp;
-
-              ftmp = color.r * 255.0;
-              itmp = ftmp;
-              dither_prob = ftmp - itmp;
-
-              if (g_rand_double (rbd->dither_rand) < dither_prob)
-                color.r += (1.0 / 255.0);
-
-              ftmp = color.g * 255.0;
-              itmp = ftmp;
-              dither_prob = ftmp - itmp;
-
-              if (g_rand_double (rbd->dither_rand) < dither_prob)
-                color.g += (1.0 / 255.0);
-
-              ftmp = color.b * 255.0;
-              itmp = ftmp;
-              dither_prob = ftmp - itmp;
-
-              if (g_rand_double (rbd->dither_rand) < dither_prob)
-                color.b += (1.0 / 255.0);
-
-              ftmp = color.a * 255.0;
-              itmp = ftmp;
-              dither_prob = ftmp - itmp;
-
-              if (g_rand_double (rbd->dither_rand) < dither_prob)
-                color.a += (1.0 / 255.0);
-
-              if (color.r > 1.0) color.r = 1.0;
-              if (color.g > 1.0) color.g = 1.0;
-              if (color.b > 1.0) color.b = 1.0;
-              if (color.a > 1.0) color.a = 1.0;
-            }

           *dest++ = color.r * 255.0;
           *dest++ = color.g * 255.0;




Servus, Daniel

Attachment: PGP.sig
Description: This is a digitally signed message part



Reply via email to