[gegl/soc-2013-opecl-ops] gegl-cl-random re-structuration, so it follows the gegl directory structure



commit 50e6a58c9a4d8974059f6aa944ccc4156802114f
Author: Carlos Zubieta <czubieta dev gmail com>
Date:   Wed Sep 4 19:22:16 2013 -0500

    gegl-cl-random re-structuration, so it follows the gegl directory structure

 gegl/gegl-random.c           |   32 ++----
 gegl/gegl.h                  |   13 ---
 gegl/opencl/Makefile.am      |    5 +-
 gegl/opencl/gegl-cl-init.c   |    4 +-
 gegl/opencl/gegl-cl-random.c |   54 ++++++++++
 gegl/opencl/gegl-cl-random.h |  231 +++++++-----------------------------------
 opencl/random.h              |  184 +++++++++++++++++++++++++++++++++
 7 files changed, 289 insertions(+), 234 deletions(-)
---
diff --git a/gegl/gegl-random.c b/gegl/gegl-random.c
index 73894d9..496417d 100644
--- a/gegl/gegl-random.c
+++ b/gegl/gegl-random.c
@@ -41,7 +41,7 @@
 
 /* a set of reasonably large primes to choose from for array sizes
  */
-static long primes[]={
+long gegl_random_primes[]={
 10007,10009,10037,10039,10061,10067,10069,10079,10091,10093,10099,10103,10111,
 10133,10139,10141,10151,10159,10163,10169,10177,10181,10193,10211,10223,10243,
 10247,10253,10259,10267,10271,10273,10289,10301,10303,10313,10321,10331,10333,
@@ -93,10 +93,10 @@ static long primes[]={
 
 #define RANDOM_DATA_SIZE (15083+15091+15101)
 
-static gint32   random_data[RANDOM_DATA_SIZE];
+gint32          gegl_random_data[RANDOM_DATA_SIZE];
 static gboolean random_data_inited = FALSE;
 
-static inline void random_init (void)
+inline void gegl_random_init (void)
 {
   if (G_LIKELY (random_data_inited))
     return;
@@ -105,7 +105,7 @@ static inline void random_init (void)
     GRand *gr = g_rand_new_with_seed (42);
     int i;
     for (i = 0; i < RANDOM_DATA_SIZE; i++)
-      random_data[i] = g_rand_int (gr);
+      gegl_random_data[i] = g_rand_int (gr);
     g_rand_free (gr);
     random_data_inited = TRUE;
   }
@@ -125,8 +125,9 @@ _gegl_random_int (int seed,
 #define ROUNDS 3
     /* 3 rounds gives a reasonably high cycle for */
                          /*   our synthesized larger random set. */
-  long * prime = &primes[seed % (G_N_ELEMENTS (primes) - 1 - ROUNDS)];
-  random_init ();
+  long * prime = &gegl_random_primes[seed % (G_N_ELEMENTS (gegl_random_primes)
+                                     - 1 - ROUNDS)];
+  gegl_random_init ();
 #define UNROLLED
 
 #ifdef UNROLLED
@@ -136,9 +137,9 @@ _gegl_random_int (int seed,
         prime1 = prime[1],
         prime2 = prime[2];
     return
-    random_data[idx % prime0] ^
-    random_data[prime0 + (idx % (prime1))] ^
-    random_data[prime0 + prime1 + (idx % (prime2))];
+    gegl_random_data[idx % prime0] ^
+    gegl_random_data[prime0 + (idx % (prime1))] ^
+    gegl_random_data[prime0 + prime1 + (idx % (prime2))];
   }
 #else
   {
@@ -147,7 +148,7 @@ _gegl_random_int (int seed,
     int offset = 0;
 
     for (i = 0; i < ROUNDS; i++) 
-      ret ^= random_data[offset + (idx % (prime[i]))];
+      ret ^= gegl_random_data[offset + (idx % (prime[i]))];
       offset += prime[i];
 
 
@@ -156,17 +157,6 @@ _gegl_random_int (int seed,
 #endif
 }
 
-gint* gegl_get_random_data_ptr(void)
-{
-  random_init();
-  return random_data;
-}
-
-gint gegl_get_random_data_size(void)
-{
-  return G_N_ELEMENTS (random_data);
-}
-
 guint32
 gegl_random_int (int seed,
                  int x,
diff --git a/gegl/gegl.h b/gegl/gegl.h
index 4833f10..772e166 100644
--- a/gegl/gegl.h
+++ b/gegl/gegl.h
@@ -1055,19 +1055,6 @@ guint32 gegl_random_int         (int seed, int x, int y, int z, int n);
  */
 float  gegl_random_float        (int seed, int x, int y, int z, int n);
 
-/**
- * gegl_get_random_data_ptr:
- * Return an integer pointer to and initialized random data vector.
- */
-gint * gegl_get_random_data_ptr       (void);
-
-/**
- * gegl_get_random_data_size:
- * Return the size of the random data vector.
- */
-gint gegl_get_random_data_size       (void);
-
-
 #define GEGL_ALIGNED __restrict__ __attribute__((__aligned__ (16)))
 
 G_END_DECLS
diff --git a/gegl/opencl/Makefile.am b/gegl/opencl/Makefile.am
index 87a896a..751666a 100644
--- a/gegl/opencl/Makefile.am
+++ b/gegl/opencl/Makefile.am
@@ -20,6 +20,7 @@ libcl_public_HEADERS = \
        gegl-cl-init.h \
        gegl-cl-types.h \
        gegl-cl-color.h \
+       gegl-cl-random.h \
        cl_d3d10.h \
        cl_ext.h \
        cl_gl_ext.h \
@@ -33,7 +34,9 @@ libcl_sources = \
        gegl-cl-init.c \
        gegl-cl-init.h \
        gegl-cl-color.c \
-       gegl-cl-color.h
+       gegl-cl-color.h \
+       gegl-cl-random.c \
+       gegl-cl-random.h
 
 noinst_LTLIBRARIES = libcl.la
 
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index b0a04c0..f21f480 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -397,8 +397,6 @@ if (errcode != CL_SUCCESS)                                          \
             #func, __LINE__, __FILE__, gegl_cl_errstring(errcode)); \
 }
 
-static const char* cl_build_options = "-I../../gegl";
-
 /* XXX: same program_source with different kernel_name[], context or device
  *      will retrieve the same key
  */
@@ -423,7 +421,7 @@ gegl_cl_compile_and_build (const char *program_source, const char *kernel_name[]
       CL_SAFE_CALL( cl_data->program = gegl_clCreateProgramWithSource(gegl_cl_get_context(), 1, 
&program_source,
                                                                       &length, &errcode) );
 
-      errcode = gegl_clBuildProgram(cl_data->program, 0, NULL, cl_build_options, NULL, NULL);
+      errcode = gegl_clBuildProgram(cl_data->program, 0, NULL, NULL, NULL, NULL);
       if (errcode != CL_SUCCESS)
         {
           char *msg;
diff --git a/gegl/opencl/gegl-cl-random.c b/gegl/opencl/gegl-cl-random.c
new file mode 100644
index 0000000..6814bee
--- /dev/null
+++ b/gegl/opencl/gegl-cl-random.c
@@ -0,0 +1,54 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 Carlos Zubieta (czubieta dev gmail com)
+ */
+
+#include <glib.h>
+#include "gegl-cl-random.h"
+#include "opencl/gegl-cl.h"
+
+/*XXX: This file has to be kept in sync whit gegl-random.c*/
+#define RANDOM_DATA_SIZE (15083+15091+15101)
+#define PRIMES_SIZE 533
+
+/*declared in gegl-random.c*/
+extern gint32      *gegl_random_data;
+extern long        *gegl_random_primes;
+extern inline void gegl_random_init (void);
+
+cl_mem gegl_cl_load_random_data(int *cl_err)
+{
+  gegl_random_init();
+  cl_mem cl_random_data;
+  cl_random_data = gegl_clCreateBuffer(gegl_cl_get_context(),
+                                       CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
+                                       RANDOM_DATA_SIZE*sizeof(gint32),
+                                       (void*) &gegl_random_data,
+                                       cl_err);
+  return cl_random_data;
+}
+
+cl_mem gegl_cl_load_random_primes(int *cl_err)
+{
+  cl_mem cl_random_primes;
+  cl_random_primes = gegl_clCreateBuffer(gegl_cl_get_context(),
+                                         CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
+                                         PRIMES_SIZE*sizeof(long),
+                                         (void*) &gegl_random_primes,
+                                         cl_err);
+  return cl_random_primes;
+}
+
diff --git a/gegl/opencl/gegl-cl-random.h b/gegl/opencl/gegl-cl-random.h
index 9d96602..b2280ab 100644
--- a/gegl/opencl/gegl-cl-random.h
+++ b/gegl/opencl/gegl-cl-random.h
@@ -1,200 +1,39 @@
-/* XXX: This file has to be kept in sync with gegl-random.c. Probably a code
-*  restructuration will avoid duplication.
-*/
-#define PRIME_SIZE 533
-
-__constant long primes[]={
-10007,10009,10037,10039,10061,10067,10069,10079,10091,10093,10099,10103,10111,
-10133,10139,10141,10151,10159,10163,10169,10177,10181,10193,10211,10223,10243,
-10247,10253,10259,10267,10271,10273,10289,10301,10303,10313,10321,10331,10333,
-10337,10343,10357,10369,10391,10399,10427,10429,10433,10453,10457,10459,10463,
-10477,10487,10499,10501,10513,10529,10531,10559,10567,10589,10597,10601,10607,
-10613,10627,10631,10639,10651,10657,10663,10667,10687,10691,10709,10711,10723,
-10729,10733,10739,10753,10771,10781,10789,10799,10831,10837,10847,10853,10859,
-10861,10867,10883,10889,10891,10903,10909,10937,10939,10949,10957,10973,10979,
-10987,10993,11003,11027,11047,11057,11059,11069,11071,11083,11087,11093,11113,
-11117,11119,11131,11149,11159,11161,11171,11173,11177,11197,11213,11239,11243,
-11251,11257,11261,11273,11279,11287,11299,11311,11317,11321,11329,11351,11353,
-11369,11383,11393,11399,11411,11423,11437,11443,11447,11467,11471,11483,11489,
-11491,11497,11503,11519,11527,11549,11551,11579,11587,11593,11597,11617,11621,
-11633,11657,11677,11681,11689,11699,11701,11717,11719,11731,11743,11777,11779,
-11783,11789,11801,11807,11813,11821,11827,11831,11833,11839,11863,11867,11887,
-11897,11903,11909,11923,11927,11933,11939,11941,11953,11959,11969,11971,11981,
-11987,12007,12011,12037,12041,12043,12049,12071,12073,12097,12101,12107,12109,
-12113,12119,12143,12149,12157,12161,12163,12197,12203,12211,12227,12239,12241,
-12251,12253,12263,12269,12277,12281,12289,12301,12323,12329,12343,12347,12373,
-12377,12379,12391,12401,12409,12413,12421,12433,12437,12451,12457,12473,12479,
-12487,12491,12497,12503,12511,12517,12527,12539,12541,12547,12553,12569,12577,
-12583,12589,12601,12611,12613,12619,12637,12641,12647,12653,12659,12671,12689,
-12697,12703,12713,12721,12739,12743,12757,12763,12781,12791,12799,12809,12821,
-12823,12829,12841,12853,12889,12893,12899,12907,12911,12917,12919,12923,12941,
-12953,12959,12967,12973,12979,12983,13001,13003,13007,13009,13033,13037,13043,
-13049,13063,13093,13099,13103,13109,13121,13127,13147,13151,13159,13163,13171,
-13177,13183,13187,13217,13219,13229,13241,13249,13259,13267,13291,13297,13309,
-13313,13327,13331,13337,13339,13367,13381,13397,13399,13411,13417,13421,13441,
-13451,13457,13463,13469,13477,13487,13499,13513,13523,13537,13553,13567,13577,
-13591,13597,13613,13619,13627,13633,13649,13669,13679,13681,13687,13691,13693,
-13697,13709,13711,13721,13723,13729,13751,13757,13759,13763,13781,13789,13799,
-13807,13829,13831,13841,13859,13873,13877,13879,13883,13901,13903,13907,13913,
-13921,13931,13933,13963,13967,13997,13999,14009,14011,14029,14033,14051,14057,
-14071,14081,14083,14087,14107,14143,14149,14153,14159,14173,14177,14197,14207,
-14221,14243,14249,14251,14281,14293,14303,14321,14323,14327,14341,14347,14369,
-14387,14389,14401,14407,14411,14419,14423,14431,14437,14447,14449,14461,14479,
-14489,14503,14519,14533,14537,14543,14549,14551,14557,14561,14563,14591,14593,
-14621,14627,14629,14633,14639,14653,14657,14699,14713,14717,14723,14731,14737,
-14741,14747,14753,14759,14767,14771,14779,14783,14797,14813,14821,14827,14831,
-14843,14851,14867,14869,14879,14887,14891,14897,14923,14929,14939,14947,14951,
-14957,14969,14983,15013,15017,15031,15053,15061,15073,15077,15083,15091,15101
-};
-
-/* these primes should not exist in the above set */
-#define XPRIME     103423
-#define YPRIME     101359
-#define NPRIME     101111
-
-#define RANDOM_DATA_SIZE (15083+15091+15101)
-
-static inline int
-_gegl_cl_random_int (__global const int *random_data,
-                     int                seed,
-                     int                x,
-                     int                y,
-                     int                z,
-                     int                n)
-{
-  unsigned long idx = x * XPRIME + 
-                      y * YPRIME * XPRIME + 
-                      n * NPRIME * YPRIME * XPRIME;
-#define ROUNDS 3
-    /* 3 rounds gives a reasonably high cycle for */
-                         /*   our synthesized larger random set. */
-  unsigned long seed_idx = seed % (PRIME_SIZE - 1 - ROUNDS);
-  int prime0 = primes[seed_idx],
-      prime1 = primes[seed_idx+1],
-      prime2 = primes[seed_idx+2];
-  int r0 = random_data[idx % prime0],
-      r1 = random_data[prime0 + (idx % (prime1))],
-      r2 = random_data[prime0 + prime1 + (idx % (prime2))];
-  return r0 ^ r1 ^ r2;
-}
-
-static inline int4
-_gegl_cl_random_int4 (__global const int *random_data,
-                      int                seed,
-                      int                x,
-                      int                y,
-                      int                z,
-                      int                n)
-{
-  int r0 = _gegl_cl_random_int(random_data, seed, x, y, z, n++);
-  int r1 = _gegl_cl_random_int(random_data, seed, x, y, z, n++);
-  int r2 = _gegl_cl_random_int(random_data, seed, x, y, z, n++);
-  int r3 = _gegl_cl_random_int(random_data, seed, x, y, z, n);
-  return (int4)(r0, r1, r2, r3);
-}
-
-int
-gegl_cl_random_int (__global const int *random_data,
-                    int                seed,
-                    int                x,
-                    int                y,
-                    int                z,
-                    int                n)
-{
-  return _gegl_cl_random_int (random_data, seed, x, y, z, n);
-}
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 Carlos Zubieta (czubieta dev gmail com)
+ */
+
+#ifndef __GEGL_CL_RANDOM_H__
+#define __GEGL_CL_RANDOM_H__
+
+#include "gegl-cl-types.h"
+/** Load the random data needed to generate random numbers in the GPU*/
+cl_mem gegl_cl_load_random_data(int *cl_err);
+
+/** Load the primes needed to generate random numbers in the GPU*/
+cl_mem gegl_cl_load_random_primes(int *cl_err);
 
-int
-gegl_cl_random_int_range (__global const int *random_data,
-                          int                seed,
-                          int                x,
-                          int                y,
-                          int                z,
-                          int                n,
-                          int                min,
-                          int                max)
-{
-  int ret = _gegl_cl_random_int (random_data, seed, x, y, z, n);
-  return (ret % (max-min)) + min;
-}
-
-int4
-gegl_cl_random_int4 (__global const int *random_data,
-                     int                seed,
-                     int                x,
-                     int                y,
-                     int                z,
-                     int                n)
-{
-  return _gegl_cl_random_int4 (random_data, seed, x, y, z, n);
-}
-
-int4
-gegl_cl_random_int4_range (__global const int *random_data,
-                           int                seed,
-                           int                x,
-                           int                y,
-                           int                z,
-                           int                n,
-                           int                min,
-                           int                max)
-{
-  int4 ret = _gegl_cl_random_int4 (random_data, seed, x, y, z, n);
-  return (ret % (max-min)) + min;
-}
-
-#define G_RAND_FLOAT_TRANSFORM  0.00001525902189669642175f
-
-float
-gegl_cl_random_float (__global const int *random_data,
-                      int                seed,
-                      int                x,
-                      int                y,
-                      int                z,
-                      int                n)
-{
-  int u = _gegl_cl_random_int (random_data, seed, x, y, z, n);
-  return convert_float(u & 0xffff) * G_RAND_FLOAT_TRANSFORM;
-}
-
-float
-gegl_cl_random_float_range (__global const int *random_data,
-                            int                seed,
-                            int                x,
-                            int                y,
-                            int                z,
-                            int                n,
-                            float              min,
-                            float              max)
-{
-  return gegl_cl_random_float (random_data, seed, x, y, z, n) * (max - min) + min;
-}
 /*
-float4
-gegl_cl_random_float4 (__gloabl int *random_data,
-                       int seed,
-                       int x,
-                       int y,
-                       int z,
-                       int n)
-{
-  float r0 = gegl_cl_random_float(random_data, seed x, y, z, n++);
-  float r1 = gegl_cl_random_float(random_data, seed x, y, z, n++);
-  float r2 = gegl_cl_random_float(random_data, seed x, y, z, n++);
-  float r3 = gegl_cl_random_float(random_data, seed x, y, z, n);
-  return (float4)(r0, r1, r2, r3);
-}
+#define GEGL_CL_LOAD_RANDOM(obj)           \
+   { obj = gegl_cl_load_random(&cl_err);   \
+    CL_CHECK;}
 
-float4
-gegl_cl_random_float4_range (int *random_data,
-                             int seed,
-                             int x,
-                             int y,
-                             int z,
-                             int n,
-                             float min,
-                             float max)
-{
-  return gegl_cl_random_float4 (random_data, seed, x, y, z, n) * (max - min) + min;
-}
+#define GEGL_CL_RELEASE_RANDOM(obj)        \
+  { cl_err = gegl_clReleaseMemObject(obj); \
+    CL_CHECK; }
 */
+
+#endif
diff --git a/opencl/random.h b/opencl/random.h
new file mode 100644
index 0000000..fa89246
--- /dev/null
+++ b/opencl/random.h
@@ -0,0 +1,184 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 Carlos Zubieta (czubieta dev gmail com)
+ */
+
+/* XXX: this file should be kept in sync with gegl-random. */
+#define XPRIME     103423
+#define YPRIME     101359
+#define NPRIME     101111
+
+#define RANDOM_DATA_SIZE (15083+15091+15101)
+#define PRIME_SIZE 533
+
+static inline int
+_gegl_cl_random_int (__global const int  *cl_random_data,
+                     __global const long *cl_random_primes,
+                     int                 seed,
+                     int                 x,
+                     int                 y,
+                     int                 z,
+                     int                 n)
+{
+  unsigned long idx = x * XPRIME + 
+                      y * YPRIME * XPRIME + 
+                      n * NPRIME * YPRIME * XPRIME;
+#define ROUNDS 3
+    /* 3 rounds gives a reasonably high cycle for */
+    /*   our synthesized larger random set. */
+  unsigned long seed_idx = seed % (PRIME_SIZE - 1 - ROUNDS);
+  int prime0 = convert_int(cl_random_primes[seed_idx]),
+      prime1 = convert_int(cl_random_primes[seed_idx+1]),
+      prime2 = convert_int(cl_random_primes[seed_idx+2]);
+  int r0 = cl_random_data[idx % prime0],
+      r1 = cl_random_data[prime0 + (idx % (prime1))],
+      r2 = cl_random_data[prime0 + prime1 + (idx % (prime2))];
+  return r0 ^ r1 ^ r2;
+}
+
+int
+gegl_cl_random_int (__global const int  *cl_random_data,
+                    __global const long *cl_random_primes,
+                    int                 seed,
+                    int                 x,
+                    int                 y,
+                    int                 z,
+                    int                 n)
+{
+  return _gegl_cl_random_int (cl_random_data, cl_random_primes,
+                              seed, x, y, z, n);
+}
+
+int
+gegl_cl_random_int_range (__global const int  *cl_random_data,
+                          __global const long *cl_random_primes,
+                          int                 seed,
+                          int                 x,
+                          int                 y,
+                          int                 z,
+                          int                 n,
+                          int                 min,
+                          int                 max)
+{
+  int ret = _gegl_cl_random_int (cl_random_data, cl_random_primes,
+                                 seed, x, y, z, n);
+  return (ret % (max-min)) + min;
+}
+
+int4
+gegl_cl_random_int4 (__global const int  *cl_random_data,
+                     __global const long *cl_random_primes,
+                     int                 seed,
+                     int                 x,
+                     int                 y,
+                     int                 z,
+                     int                 n)
+{
+  int r0 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
+                               seed, x, y, z, n);
+  int r1 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
+                               seed, x, y, z, n+1);
+  int r2 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
+                               seed, x, y, z, n+2);
+  int r3 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
+                               seed, x, y, z, n+3);
+  return (int4)(r0, r1, r2, r3);
+}
+
+int4
+gegl_cl_random_int4_range (__global const int  *cl_random_data,
+                           __global const long *cl_random_primes,
+                           int                 seed,
+                           int                 x,
+                           int                 y,
+                           int                 z,
+                           int                 n,
+                           int                 min,
+                           int                 max)
+{
+  int4 ret = gegl_cl_random_int4 (cl_random_data, cl_random_primes,
+                                  seed, x, y, z, n);
+  return (ret % (max-min)) + min;
+}
+
+#define G_RAND_FLOAT_TRANSFORM  0.00001525902189669642175f
+
+float
+gegl_cl_random_float (__global const int  *cl_random_data,
+                      __global const long *cl_random_primes,
+                      int                 seed,
+                      int                 x,
+                      int                 y,
+                      int                 z,
+                      int                 n)
+{
+  int u = _gegl_cl_random_int (cl_random_data, cl_random_primes,
+                               seed, x, y, z, n);
+  return convert_float(u & 0xffff) * G_RAND_FLOAT_TRANSFORM;
+}
+
+float
+gegl_cl_random_float_range (__global const int  *cl_random_data,
+                            __global const long *cl_random_primes,
+                            int                 seed,
+                            int                 x,
+                            int                 y,
+                            int                 z,
+                            int                 n,
+                            float               min,
+                            float               max)
+{
+  float f = gegl_cl_random_float (cl_random_data, cl_random_primes,
+                                  seed, x, y, z, n);
+  return f * (max - min) + min;
+}
+
+float4
+gegl_cl_random_float4 (__global const int  *cl_random_data,
+                       __global const long *cl_random_primes,
+                       int                 seed,
+                       int                 x,
+                       int                 y,
+                       int                 z,
+                       int                 n)
+{
+  float r0 = gegl_cl_random_float(cl_random_data, cl_random_primes,
+                                  seed x, y, z, n);
+  float r1 = gegl_cl_random_float(cl_random_data, cl_random_primes,
+                                  seed x, y, z, n+1);
+  float r2 = gegl_cl_random_float(cl_random_data, cl_random_primes,
+                                  seed x, y, z, n+2);
+  float r3 = gegl_cl_random_float(cl_random_data, cl_random_primes,
+                                  seed x, y, z, n+3);
+  return (float4)(r0, r1, r2, r3);
+}
+
+float4
+gegl_cl_random_float4_range (__global const int  *cl_random_data,
+                             __global const long *cl_random_primes,
+                             int                 seed,
+                             int                 x,
+                             int                 y,
+                             int                 z,
+                             int                 n,
+                             float               min,
+                             float               max)
+{
+  float4 f = gegl_cl_random_float4 (cl_random_data, cl_random_primes,
+                                    seed, x, y, z, n);
+  return f4 * (float4)((max - min) + min);
+}
+


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