1 /* This file is part of GEGL
3 * GEGL is free software
; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation
; either
6 * version
3 of the License
, or
(at your option
) any later version.
8 * GEGL is distributed in the hope that it will be useful
,
9 * but WITHOUT ANY WARRANTY
; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with GEGL
; if not, see <https://www.gnu.org/licenses/>.
16 * Copyright
2013 Carlos Zubieta
(czubieta.dev
@gmail.com
)
19 /* XXX
: this file should be kept in sync with gegl-random.
*/
21 typedef ushort4 GeglRandom
;
23 unsigned int _gegl_cl_random_int
(__global const int
*cl_random_data
,
24 const GeglRandom rand
,
30 unsigned int gegl_cl_random_int
(__global const int
*cl_random_data
,
31 const GeglRandom rand
,
37 int gegl_cl_random_int_range
(__global const int
*cl_random_data
,
38 const GeglRandom rand
,
46 float gegl_cl_random_float
(__global const int
*cl_random_data
,
47 const GeglRandom rand
,
53 float gegl_cl_random_float_range
(__global const int
*cl_random_data
,
54 const GeglRandom rand
,
63 _gegl_cl_random_int
(__global const int
*cl_random_data
,
64 const GeglRandom rand
,
70 const long XPRIME
= 103423;
71 const long YPRIME
= 101359;
72 const long NPRIME
= 101111;
74 unsigned long idx
= x
* XPRIME
+
76 n
* NPRIME
* YPRIME
* XPRIME
;
78 int r0
= cl_random_data
[idx % rand.x
],
79 r1
= cl_random_data
[rand.x
+ (idx % rand.y
)],
80 r2
= cl_random_data
[rand.x
+ rand.y
+ (idx % rand.z
)];
85 gegl_cl_random_int
(__global const int
*cl_random_data
,
86 const GeglRandom rand
,
92 return _gegl_cl_random_int
(cl_random_data, rand
, x
, y
, z
, n
);
96 gegl_cl_random_int_range
(__global const int
*cl_random_data
,
97 const GeglRandom rand
,
105 int ret
= _gegl_cl_random_int
(cl_random_data, rand
, x
, y
, z
, n
);
106 return
(ret %
(max-min)) + min
;
110 #define G_RAND_FLOAT_TRANSFORM
0.00001525902189669642175f
113 gegl_cl_random_float
(__global const int
*cl_random_data
,
114 const GeglRandom rand
,
120 int u
= _gegl_cl_random_int
(cl_random_data, rand
, x
, y
, z
, n
);
121 return
(u & 0xffff) * G_RAND_FLOAT_TRANSFORM
;
125 gegl_cl_random_float_range
(__global const int
*cl_random_data
,
126 const GeglRandom rand
,
134 float f
= gegl_cl_random_float
(cl_random_data, rand
, x
, y
, z
, n
);
135 return f
* (max - min
) + min
;