Update Portuguese translation
[gegl.git] / opencl / random.cl
blob03e2ae10d002ba0563216e92a156ad740ecc548b
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,
25 int x,
26 int y,
27 int z,
28 int n);
30 unsigned int gegl_cl_random_int (__global const int *cl_random_data,
31 const GeglRandom rand,
32 int x,
33 int y,
34 int z,
35 int n);
37 int gegl_cl_random_int_range (__global const int *cl_random_data,
38 const GeglRandom rand,
39 int x,
40 int y,
41 int z,
42 int n,
43 int min,
44 int max);
46 float gegl_cl_random_float (__global const int *cl_random_data,
47 const GeglRandom rand,
48 int x,
49 int y,
50 int z,
51 int n);
53 float gegl_cl_random_float_range (__global const int *cl_random_data,
54 const GeglRandom rand,
55 int x,
56 int y,
57 int z,
58 int n,
59 float min,
60 float max);
62 unsigned int
63 _gegl_cl_random_int (__global const int *cl_random_data,
64 const GeglRandom rand,
65 int x,
66 int y,
67 int z,
68 int n)
70 const long XPRIME = 103423;
71 const long YPRIME = 101359;
72 const long NPRIME = 101111;
74 unsigned long idx = x * XPRIME +
75 y * YPRIME * 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)];
81 return r0 ^ r1 ^ r2;
84 unsigned int
85 gegl_cl_random_int (__global const int *cl_random_data,
86 const GeglRandom rand,
87 int x,
88 int y,
89 int z,
90 int n)
92 return _gegl_cl_random_int (cl_random_data, rand, x, y, z, n);
95 int
96 gegl_cl_random_int_range (__global const int *cl_random_data,
97 const GeglRandom rand,
98 int x,
99 int y,
100 int z,
101 int n,
102 int min,
103 int max)
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
112 float
113 gegl_cl_random_float (__global const int *cl_random_data,
114 const GeglRandom rand,
115 int x,
116 int y,
117 int z,
118 int n)
120 int u = _gegl_cl_random_int (cl_random_data, rand, x, y, z, n);
121 return (u & 0xffff) * G_RAND_FLOAT_TRANSFORM;
124 float
125 gegl_cl_random_float_range (__global const int *cl_random_data,
126 const GeglRandom rand,
127 int x,
128 int y,
129 int z,
130 int n,
131 float min,
132 float max)
134 float f = gegl_cl_random_float (cl_random_data, rand, x, y, z, n);
135 return f * (max - min) + min;